import { useEffect,useState } from "react"
import { getChannelsAPI } from "@/apis/article"


function useChannel(){
    //1.使用useState初始化数据和修改数据的方法
    const [channels,setChannels]=useState([])

    //2.使用useEffect调用接口并保存数据
    useEffect(()=>{
        async function fetchChannels() {
            const res= await getChannelsAPI()
            setChannels(res.data.channels)
        }
        fetchChannels()
    },[])
    return{
        channels
    }
}

export{useChannel}
